<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<!--
 Licensed to the Apache Software Foundation (ASF) under one or more
 contributor license agreements.  See the NOTICE file distributed with
 this work for additional information regarding copyright ownership.
 The ASF licenses this file to You under the Apache License, Version 2.0
 (the "License"); you may not use this file except in compliance with
 the License.  You may obtain a copy of the License at

     http://www.apache.org/licenses/LICENSE-2.0

 Unless required by applicable law or agreed to in writing, software
 distributed under the License is distributed on an "AS IS" BASIS,
 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 See the License for the specific language governing permissions and
 limitations under the License.
-->

<html><head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Storm UI</title>
<link href="/css/bootstrap-3.3.1.min.css" rel="stylesheet" type="text/css">
<link href="/css/jquery.dataTables.1.10.4.min.css" rel="stylesheet" type="text/css">
<link href="/css/dataTables.bootstrap.css" rel="stylesheet" type="text/css">
<link href="/css/jsonFormatter.min.css" rel="stylesheet" type="text/css">
<link href="/css/style.css?_ts=${packageTimestamp}" rel="stylesheet" type="text/css">
<script src="/js/jquery-3.5.1.min.js" type="text/javascript"></script>
<script src="/js/jquery.dataTables.1.10.4.min.js" type="text/javascript"></script>
<script src="/js/jquery.cookies.2.2.0.min.js" type="text/javascript"></script>
<script src="/js/jquery.mustache.js" type="text/javascript"></script>
<script src="/js/url.min.js" type="text/javascript"></script>
<script src="/js/bootstrap-3.3.1.min.js" type="text/javascript"></script>
<script src="/js/jquery.blockUI.min.js" type="text/javascript"></script>
<script src="/js/jsonFormatter.min.js" type="text/javascript"></script>
<script src="/js/script.js?_ts=${packageTimestamp}" type="text/javascript"></script>
<script src="/js/dataTables.bootstrap.min.js" type="text/javascript"></script>
</head>
<body>
<div class="supervisor-page container-fluid">
  <div class="row">
    <div class="col-md-11">
      <h1><a href="/">Storm UI</a></h1>
    </div>
    <div id="ui-user" class="col-md-1"></div>
  </div>
  <div class="row">
    <div class="col-md-12">
      <h2>Supervisor summary</h2>
      <div id="supervisor-summary"></div>
    </div>
  </div>
  <div class="row">
    <div class="col-md-12">
      <h2 id="worker-resources-header">Worker resources</h2>
      <div id="worker-resources"></div>
    </div>
  </div>
  <div class="row">
    <div class="col-md-12">
      <span id="toggle-sys" style="display: block;" class="js-only"></span>
    </div>
  </div>
  <div class="row">
    <div id="json-response-error"></div>
  </div>
  <div>
    <p id="page-rendered-at-timestamp"></p>
  </div>
</div>
</body>

<script>
    
$(document).ajaxStop($.unblockUI);
$(document).ajaxStart(function(){
    $.blockUI({ message: '<img src="images/spinner.gif" /> <h3>Loading summary...</h3>'});
});
function jsError(other) {
    try {
      other();
    } catch (err) {
      getStatic("/templates/json-error-template.html", function(template) {
        $("#json-response-error").append(Mustache.render($(template).filter("#json-error-template").html(),{error: "JS Error", errorMessage: err}));
      });
    }
}

$(document).ready(function() {
    var supervisorId = $.url("?id");
    var host = $.url("?host");
    var windowParam = $.url("?window");
    var sys = $.cookies.get("sys") || "false";
    var url = "/api/v1/supervisor?" + 
                (supervisorId ? "id="+supervisorId : "host="+host) 
                + "&sys="+sys;
    if(windowParam) url += "&window=" + windowParam;
    $.extend( $.fn.dataTable.defaults, {
      stateSave: true,
      lengthMenu: [[20,40,60,100,-1], [20, 40, 60, 100, "All"]],
      pageLength: 20
    });

    renderToggleSys($("#toggle-sys"));

    var supervisorSummary = $("#supervisor-summary");
    var workerStats = $("#worker-resources");

    $.ajaxSetup({
        "error":function(jqXHR,textStatus,response) {
            var errorJson = jQuery.parseJSON(jqXHR.responseText);
            getStatic("/templates/json-error-template.html", function(template) {
                $("#json-response-error").append(Mustache.render($(template).filter("#json-error-template").html(),errorJson));
            });
        }
    });

    $.getJSON(url,function(response,status,jqXHR) {
        getStatic("/templates/supervisor-page-template.html", function(template) {
            jsError(function() {
                supervisorSummary.append(
                        Mustache.render($(template).filter("#supervisor-summary-template").html(),response));
                var displayResource = response["schedulerDisplayResource"];
                if (displayResource){
                  // (0) host, (1) supervisor id, (2) uptime, (3) slots, (4) used slots, (5) total mem (6) used mem,
                  // (7) availMem (8) totalCpu (9) usedCpu (10) availCpu (11) totalGenericResources
                  // (12) usedGenericResources (13) availGenericResources (14) version, (15) blacklisted
                  dtAutoPage("#supervisor-summary-table", {
                    columnDefs: [
                      {type: "num", targets: [3, 4]},
                      {type: "num", targets: [5, 6, 7, 8, 9, 10, 11, 12, 13], render: $.fn.dataTable.render.number(',', '.', 0)},
                      {type: "time-str", targets: [2]}
                    ]
                  });
                } else {
                  // (0) host, (1) supervisor id, (2) uptime, (3) slots, (4) used slots, (5) used mem, (6) version, (7) blacklisted
                  dtAutoPage("#supervisor-summary-table", {
                    columnDefs: [
                      {type: "num", targets: [3, 4]},
                      {type: "num", targets: [5], render: $.fn.dataTable.render.number(',', '.', 0)},
                      {type: "time-str", targets: [2]}
                    ]
                  });
                }

                $('#supervisor-summary-table [data-toggle="tooltip"]').tooltip();
                workerStats.append(Mustache.render($(template).filter("#worker-stats-template").html(),response));
                makeSupervisorWorkerStatsTable(response, '#worker-stats-table', '#worker-resources');
            });
        });
    });
});

getPageRenderedTimestamp("page-rendered-at-timestamp");

</script>
